package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.lifecycle.ViewModelProvider;

import com.bumptech.glide.Glide;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;
import com.zlzxm.shoesmarket.viewmodel.VMAccount;
import com.zlzxm.shoesmarket.viewmodel.entity.EntityAccount;

/**
 * CREATE BY zlzxm ON 4/13/21
 */
public class ACAccount extends BaseActivity{

    public static void start(Context context){

        Intent intent = new Intent(context,ACAccount.class);

        context.startActivity(intent);

    }


    VMAccount vmAccount;

    private ImageView ivFace;

    private TextView tvNick,tvPhone,tvIsWXBind;


    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_account);

        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);

        simpleHead.setTitle("我的账户");
        simpleHead.setOnItemclicklistener(this::finish);

        ivFace = ZViewHelp.findById(this,R.id.ivFace);
        tvNick = ZViewHelp.findById(this,R.id.tvNick);
        tvPhone = ZViewHelp.findById(this,R.id.tvPhone);
        tvIsWXBind = ZViewHelp.findById(this,R.id.tvIsWXBind);
    }

    @Override
    protected void initViewModule() {
        super.initViewModule();
        vmAccount = new ViewModelProvider(this).get(VMAccount.class);

        vmAccount.getLiveAccount().observe(this,this::updateAccount);
    }

    @Override
    protected void initData() {
        super.initData();
        vmAccount.requestAccount();
    }


    //<editor-fold defaultState="collapsed" desc="测试">


    private void updateAccount(EntityAccount entityAccount){

        Glide.with(this)
                .load(entityAccount.getFace())
                .circleCrop()
                .into(ivFace);

        tvNick.setText(entityAccount.getNick());
        tvPhone.setText(entityAccount.getPhone());
        tvIsWXBind.setText(entityAccount.getBindWx()?"已绑定":"未绑定");

    }

    // </editor-fold>
}
